package pos.domain;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import pos.data.JDBCPlantaDAO;


public class wiki {
	private List plantaswiki;
	
	private static wiki wk;
	
	public static synchronized wiki getInstance(){
		if(wk==null)
			wk=new wiki();
		return wk;
	}
	
	private wiki() {
		
		plantaswiki = (new JDBCPlantaDAO()).selectAllPlantas();
	}

	
	
public List listarPlantas() {
	return plantaswiki;
	
}
public planta getPlanta(String plantaid) {
		planta p1 = null;
		for (Iterator iter = this.plantaswiki.iterator(); iter.hasNext();) {
			planta p = (planta) iter.next();
			if (p.getNombreComun().compareTo(plantaid) == 0) {
				p1 = p;
			}
		}
		return p1;
	}
	public boolean addPlanta(planta p) {
		boolean add=false;
		if(plantaswiki.add(p))
			add=true;
		return add;
	}
	public boolean modPlanta(planta p) {
		
		boolean enc = false;
		Iterator it = plantaswiki.iterator();
		while(it.hasNext() && !enc) {
			Object o = (planta) it.next();
			if(o.equals(p)) {
				p=(planta) o;
				enc=true;
			}
		}
		return enc;
	}
	public class buscador {
		public planta buscarPlanta(String nombre) {
			planta p1 = null;
			for (Iterator iter = plantaswiki.iterator(); iter.hasNext();) {
				 planta p = (planta) iter.next();
				if (p.getNombreComun().compareTo(nombre) == 0) {
					p1 = p;
				}
			}
			return p1;
		}
		public List buscarPlantaCat(String categoria) {
			List l = new LinkedList();
			for (Iterator iter = plantaswiki.iterator(); iter.hasNext();) {
				planta p = (planta) iter.next();
				if (p.getCategoria().compareTo(categoria) == 0)
					l.add(p);
				}
			return l;
		}

}

}
